<?php
/** 
 * Copyright (C) 2009 João Neto
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * @version JLojaController.php - 19/07/2009 - joaoneto
 * @package lib/controller
 */
defined( '_JEXEC' ) or die( 'Restricted access' ); //no direct access

jimport( 'joomla.application.component.controller' );

class JLoja_Controller extends JController
{
	/**
	 * Method to get a reference to the current view and load it if necessary.
	 *
	 * @access	public
	 * @param	string	The view name. Optional, defaults to the controller
	 * name.
	 * @param	string	The view type. Optional.
	 * @param	string	The class prefix. Optional.
	 * @param	array	Configuration array for view. Optional.
	 * @return	Jloja_View	Reference to the view or an error.
	 */
	public function getView( $name, $type = '', $prefix = '' )
	{
		if( $prefix ){
			$prefix = $prefix . 'View';
		}

		return parent::getView($name, $type, $prefix );
	}

	/**
	 * Get a JLoja_Model
	 * @param string $modelName
	 * @return JLoja_Model
	 */
	public function getModel( $modelName )
	{
		$modelLoader = new JLoja_Loader();
		return $modelLoader->loadModel( $modelName );
	}

	public function toAction( $actionName, $message=false, $type = 'message' )
	{
		if( $message ){
			JFactory::getApplication()->enqueueMessage( $message, $type );
		}
		$this->$actionName();
		return;
	}
	/**
	 * Get a JLoja_Model
	 * @param string $modelName
	 * @return JLoja_Model
	 */
	public function getTable( $modelName )
	{
		$modelLoader = new JLoja_Loader();
		return $modelLoader->loadTable( $modelName );
	}
}